import CustomNavBar from '@/components/StandNavBar/CustomNavBar';
import Redirect from '@/components/StandSearch/Redirect';
import { View } from '@tarojs/components';
import Taro from '@tarojs/taro';
import React from 'react';
import { TopCustomNavBarTitleLocation } from '../constants';
import styles from './index.weapp.module.scss';

const SearchNavBar = ({ position, title, navBarTitleLocation, placeholder, onDbClick }) => {
  return (
    <CustomNavBar
      position={position}
      className={`${styles.SearchNavBar}  customNavigationBarStyle`}
      menuBlock
    >
      <View className="wrap">
        {navBarTitleLocation === TopCustomNavBarTitleLocation.left && (
          <>
            <View className="title nav-left" onClick={onDbClick}>
              {title}
            </View>

            <Redirect
              className="search nav-right"
              placeholder={placeholder}
              showBtn={false}
              onClick={() => {
                Taro.navigateTo({ url: '/mainSubPack/searchResult/index' });
              }}
            />
          </>
        )}

        {navBarTitleLocation === TopCustomNavBarTitleLocation.center && (
          <>
            <Redirect
              className="search nav-left"
              placeholder={placeholder}
              showBtn={false}
              onClick={() => {
                Taro.navigateTo({ url: '/mainSubPack/searchResult/index' });
              }}
            />

            <View className="title nav-right" onClick={onDbClick}>
              {title}
            </View>
          </>
        )}
      </View>
    </CustomNavBar>
  );
};

export default SearchNavBar;
